<script language="javascript" type="text/javascript" src="js/ajaxupload.3.5.js"></script>
{literal}
<script type="text/javascript">
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: 'controller.php?task=addpromobanner',
			name: 'uploadfile',
			onSubmit: function(file, ext){
				 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
					status.text('Only JPG, PNG or GIF files are allowed');
					return false;
				}
				status.text('Uploading...');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				//Add uploaded file to list
				if(response==="success"){
					loadPage("promobanner/index");
					$("#message_area").show();
					$("#message_area").html("<span class='success'>Banner has been successfully uploaded.</span>");
					$('<li></li>').appendTo('#files').html('<img src="../images/banners/thumbs/'+file+'" alt="" width="100" height="100" /><br />').addClass('success');
				} else{
					//$('<li></li>').appendTo('#files').text(file).addClass('error');
					loadPage("promobanner/index");
					$("#message_area").show();
					//$("#message_area").html("<span class='error'>Sorry. Banner is already uploaded. Please select another image.</span>");
					
				}
			}
		});
		
	});

	
</script>
{/literal}
<div id="page-heading">
	<h1>{$title}</h1>
</div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td width="15%" height="100" align="center" valign="top">		
			<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
          		<tr>
            		<th align="left" class="table-header-repeat">&nbsp;</th>
          		</tr>
          		<tr>
            		<td>
            			<div id="upload">Upload File</div>
            			<!--<div id="browsepromobanner" onclick="browseAll();"><span>Browse All<span></div>    -->
            		</td>
          		</tr>
      		</table>
      	</td>
      	<td width="2%">&nbsp;</td>	
        <td width="68%" valign="top" align="center">
        	<span id="status" ></span>		
			<ul id="files" ></ul>			
			{if !empty($promobanner_arr)} 
			<div id="showimages">
				<ul id="gal_files photos">
					{section name=sec1 loop=$promobanner_arr}
                                    <li><a href="../images/promobanners/{$promobanner_arrc}"><img width="175" height="60" id="{$promobanner_arr[sec1].promobanner_id}" alt="{$promobanner_arr[sec1].url}" alt="{$promobanner_arr[sec1].filename}" src="../images/promobanner/thumbs/{$promobanner_arr[sec1].filename}" alt="" width="100" height="100" /></a><br /><img src="images/icons/remove.png" class="cursor" onclick="delpromoimage({$promobanner_arr[sec1].promobanner_id})" /></li>
                                    <h4>{$promobanner_arr[sec1].url}</h4>
                                    <input onblur="updategalurl(this.id,this.value)" id="{$promobanner_arr[sec1].promobanner_id}" type="text" name="url" value="{$promobanner_arr[sec1].url}"  />
                                   <br>   <input {$promobanner_arr[sec1].newwindow}  onchange="updatenewwindow(this.value)" id="chk{$promobanner_arr[sec1].promobanner_id}" type="checkbox" name="newwindow" value="{$promobanner_arr[sec1].promobanner_id}"  /> Open in new window
                                    {/section}
				</ul>
			</div>
			{else}
			<div id="showimages">Sorry. Currently promobanner is empty.</div>
			{/if}
        </td>		
	</tr>	
</table>

<script type="text/javascript">

function delpromoimage(promo_id)
{ldelim}
	var msg = confirm("Are you sure you want to delete this image?")
	if (msg){ldelim}
		$.ajax({ldelim}
			type: "POST",
			url: 'controller.php?task=delpromoimage',
			data: ({ldelim}promo_id: promo_id{rdelim}),
	    	success: function(data, textStatus, XMLHttpRequest){ldelim}
	    	   	if(data != '') {ldelim}
                            alert("successfully deleted the image");
	    			$("#message_area").html(data);
	    			loadPage('promobanner/index');
	    	   	{rdelim}
	    	{rdelim},
	    	complete: function complete(XMLHttpRequest, textStatus){ldelim}
	            //$("#loader_area").hide();
	        {rdelim}
		{rdelim});
	{rdelim} else {ldelim}
		return false;
	{rdelim}
{rdelim}

    function updategalurl(id,val){ldelim}
          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({ldelim}
		type: "POST",
		url: 'controller.php?task=updatepromourl',
                data: ({ldelim}promo_id: id,url:val{rdelim}),
    	success: function(data, textStatus, XMLHttpRequest){ldelim}
    	   	if(data != '') {ldelim}
                       alert("successfully updated the link");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                        loadPage('promobanner/index');
    	   	{rdelim}
    	{rdelim},
    	complete: function complete(XMLHttpRequest, textStatus){ldelim}
            //$("#loader_area").hide();
        {rdelim}
	{rdelim});

{rdelim}

    function updatenewwindow(val){ldelim}
    //alert(val);
          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');
                if($('#chk'+val).is(':checked')) {ldelim}
                         var isnewwindow='checked';
                {rdelim}
                else{ldelim}
                      var isnewwindow='';
                {rdelim}
        //  alert(isnewwindow);
		$.ajax({ldelim}
		type: "POST",
		url: 'controller.php?task=updatepromonewwindow',
                data: ({ldelim}promoid:val,isnewwindowval: isnewwindow{rdelim}),
    	success: function(data, textStatus, XMLHttpRequest){ldelim}
    	   	if(data != '') {ldelim}
                       alert("successfully updated the target ");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                        loadPage('promobanner/index');
    	   	{rdelim}
    	{rdelim},
    	complete: function complete(XMLHttpRequest, textStatus){ldelim}
            //$("#loader_area").hide();
        {rdelim}
	{rdelim});

{rdelim}


</script>